**----------------------------------------------------------------------------**
**--Local Corruption & Household Business Tax Compliance
**--Duong Le, Eddy Malesky, Anh Pham
**--Journal of Economic Behavior and Organization (July 2020)
**----------------------------------------------------------------------------**
**--Do File: Producing all Tables in the paper
**----------------------------------------------------------------------------**

clear all 
set more off
set matsize 11000 

**specify your main directory that stores all replication files
global main_directory = "insert your working directory here" 

//Replace with your data directory
cd "$main_directory\data"

//Replace with the folder you want to store all result outputs
global result "$main_directory\result"


**----------------------------------------------------------------------------**
**---Table 1: 2017 PCI Summary Statistics
**----------------------------------------------------------------------------**
use "pci.dta", clear

label var pciECindex "Entry"
label var pciLAindex "Land" 
label var pciTindex "Transparency"
label var pciTCindex "Time"
label var pciICindex "Bribe"
label var pciBindex "BiasSOE"
label var pciPindex "Proactivity"
label var pciBSSindex "Businesses Services"
label var pciLTindex "Labor training"
label var pciLIindex "Legal"

gen corruption = 11 - pciICindex
label var corruption "Corruption"

preserve
keep if year==2017
estpost sum pciECindex pciLAindex pciTindex pciTCindex pciICindex pciBindex pciPindex pciBSSindex pciLTindex pciLIindex
eststo 

esttab using "$result/PCI2017_summary_stat.tex", cells ("mean(fmt(3)) sd(fmt(3)) min(fmt(3)) max(fmt(3))") label nonumber b(%12.2f) ///
title("Summary statistics of PCI subindices in 2017") replace
restore


****
use "firm_commune_pair.dta", clear

global X_ctrls= "age sex i.educ i.location"
global C_GIS_ctrls = "area_km2 boundary_km lat lon"
global C_geo=" elev river suit_rice suit_tea suit_coffee suit_coconut suit_sugar slope tem precip"
global C_policy_ctrls = "ezone_c izone_c taxreduc"
global econ_formal= "nfirmf ld_endme ld_endm ts_asset_endme ts_asset_endm kqkd_rev_busme kqkd_rev_busm kqkd_prof_bftaxme kqkd_prof_bftaxm"
global C_governance="pciECindex_1 pciLAindex_1 pciTindex_1 pciTCindex_1  pciBindex_1 pciPindex_1 pciBSSidex_1 pciLTindex_1 pciLIindex_1"


**----------------------------------------------------------------------------**
**---Table 2: summary statistics of the dataset in the regression
**----------------------------------------------------------------------------**
global X_ctrls= "age sex i.educ i.location"
global C_GIS_ctrls = "area_km2 boundary_km lat lon"
global C_geo=" elev river suit_rice suit_tea suit_coffee suit_coconut suit_sugar slope tem precip"
global C_policy_ctrls = "ezone_c izone_c taxreduc"
global econ_formal= "nfirmf ld_endme ld_endm ts_asset_endme ts_asset_endm kqkd_rev_busme kqkd_rev_busm kqkd_prof_bftaxme kqkd_prof_bftaxm"
global C_governance="pciECindex_1 pciLAindex_1 pciTindex_1 pciTCindex_1  pciBindex_1 pciPindex_1 pciBSSidex_1 pciLTindex_1 pciLIindex_1"


**----------------------------------------------------------------------------**
**---Table 2: summary statistics of the dataset in the regression
**----------------------------------------------------------------------------**
global sum_var = "taxid lnthudn1_99 worker_total_99 taxComp taxComp_imp operation_hr rest manu retail wholesale age male notraining house"

preserve
eststo clear
duplicates drop id_nganh, force

**---sumstat for border census
estpost sum $sum_var if thudn1>100000& thudn1<. 
est store border_a
 
**---sumstat for border sample
estpost sum $sum_var if thudn1>100000& thudn1<.& phieu!=""
est store border_b
 
esttab border_a border_b using "$result\Table2.xls", mtitles("Border Census"   "Border Sample") ///
replace cells("count mean sd min max") label varwidth(60) nonumber f noobs
restore

**----------------------------------------------------------------------------**
**---Table 3: Dep Var = taxID
**----------------------------------------------------------------------------**
foreach var in taxid {	
	reghdfe `var' pciICindex_1 if thudn1>100000& thudn1<. , absorb(com_pairID ind3) cluster(provinceID_2017 borderID) 
	outreg2 using "$result/Table3.xls", replace excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder, Commune-pair FE, Yes, 3-digit Industry FE, Yes) label 
   
	    
	reghdfe `var' pciICindex_1 $C_governance if thudn1>100000& thudn1<. , absorb(com_pairID ind3) cluster(provinceID_2017 borderID) 
	outreg2 using "$result/Table3.xls", excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder, Commune-pair FE, Yes, 3-digit Industry FE, Yes, Governance controls, Yes) label 
	
	
	reghdfe `var' pciICindex_1 $C_governance $X_ctrls if thudn1>100000& thudn1<. , absorb(com_pairID ind3) cluster(provinceID_2017 borderID) 
	outreg2 using "$result/Table3.xls", excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder, Commune-pair FE, Yes, 3-digit Industry FE, Yes, Governance controls, Yes, Firm's controls, Yes) label 


	reghdfe `var' pciICindex_1  $C_governance $X_ctrls $C_policy_ctrls  $C_GIS_ctrls light16_mean $C_geo if thudn1>100000& thudn1<. , absorb(com_pairID ind3) cluster(provinceID_2017 borderID)	
	outreg2 using "$result/Table3.xls", excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder, Commune-pair FE, Yes, 3-digit Industry FE, Yes, Governance controls, Yes, Firm's controls, Yes, Commune's policy controls, Yes, Commune's GIS controls, Yes, Night-light Index 2016, Yes, Geographical controls, Yes) label 
	

			
	reghdfe `var' pciICindex_1  $C_governance $X_ctrls $C_policy_ctrls  $C_GIS_ctrls light16_mean $C_geo  $econ_formal if thudn1>100000& thudn1<. ,  absorb(com_pairID ind3) cluster(provinceID_2017 borderID)	
	outreg2 using "$result/Table3.xls", excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder, Commune-pair FE, Yes, 3-digit Industry FE, Yes, Governance controls, Yes, Firm's controls, Yes, Commune's policy controls, Yes, Commune's GIS controls, Yes, Night-light Index 2016, Yes, Geographical controls, Yes, Formal sector activities controls, Yes) label 
}

**----------------------------------------------------------------------------**
**---Table 4: Dep Var = taxid_surveySample 
**----------------------------------------------------------------------------**
foreach var in taxid_surveySample {	
	reghdfe `var' pciICindex_1 if thudn1>100000& thudn1<. , absorb(com_pairID ind3) cluster(provinceID_2017 borderID) 
	outreg2 using "$result/Table4.xls", replace excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder, Commune-pair FE, Yes, 3-digit Industry FE, Yes) label 
	    
	reghdfe `var' pciICindex_1 $C_governance if thudn1>100000& thudn1<. , absorb(com_pairID ind3) cluster(provinceID_2017 borderID) 
	outreg2 using "$result/Table4.xls", excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder, Commune-pair FE, Yes, 3-digit Industry FE, Yes, Governance controls, Yes) label 
	
	reghdfe `var' pciICindex_1 $C_governance $X_ctrls worker_total if thudn1>100000& thudn1<. , absorb(com_pairID ind3) cluster(provinceID_2017 borderID) 
	outreg2 using "$result/Table4.xls", excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder, Commune-pair FE, Yes, 3-digit Industry FE, Yes, Governance controls, Yes, Firm's controls, Yes) label 

	reghdfe `var' pciICindex_1  $C_governance $X_ctrls worker_total $C_policy_ctrls  $C_GIS_ctrls light16_mean $C_geo if thudn1>100000& thudn1<. &econ_formal==1, absorb(com_pairID ind3) cluster(provinceID_2017 borderID)	
	outreg2 using "$result/Table4.xls", excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder, Commune-pair FE, Yes, 3-digit Industry FE, Yes, Governance controls, Yes, Firm's controls, Yes, Commune's policy controls, Yes, Commune's GIS controls, Yes, Night-light Index 2016, Yes, Geographical controls, Yes) label 
	
			
	reghdfe `var' pciICindex_1  $C_governance $X_ctrls worker_total $C_policy_ctrls  $C_GIS_ctrls light16_mean $C_geo $econ_formal if thudn1>100000& thudn1<. ,  absorb(com_pairID ind3) cluster(provinceID_2017 borderID)	
	outreg2 using "$result/Table4.xls", excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder, Commune-pair FE, Yes, 3-digit Industry FE, Yes, Governance controls, Yes, Firm's controls, Yes, Commune's policy controls, Yes, Commune's GIS controls, Yes, Night-light Index 2016, Yes, Geographical controls, Yes, Formal sector activities controls, Yes) label
}



	
**----------------------------------------------------------------------------**
**---Table 5: Pairwise regressions -- tax compliance ratio
**----------------------------------------------------------------------------**
foreach var in taxComp taxComp_imp {	
	reghdfe `var' pciICindex_1  $C_governance $X_ctrls worker_total $C_policy_ctrls  $C_GIS_ctrls light16_mean $C_geo  $econ_formal if thudn1>100000& thudn1<.  ,  absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
	outreg2 using "$result/Table5.xls", excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder, Commune-pair FE, Yes, 3-digit Industry FE, Yes, Governance controls, Yes, Firm's controls, Yes, Commune's policy controls, Yes, Commune's GIS controls, Yes, Night-light Index 2016, Yes, Geographical controls, Yes, Formal sector activities controls, Yes) label
	
	reghdfe `var'  pciICindex_1  $C_governance $X_ctrls $C_policy_ctrls  $C_GIS_ctrls light16_mean $C_geo  $econ_formal if thudn1>100000& thudn1<.   & taxid==1,  absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
	outreg2 using "$result/Table5.xls", excel keep(pciICindex_1) ///
	nocons addtext(Sample, atBorder, Commune-pair FE, Yes, 3-digit Industry FE, Yes, Governance controls, Yes, Firm's controls, Yes, Commune's policy controls, Yes, Commune's GIS controls, Yes, Night-light Index 2016, Yes, Geographical controls, Yes, Formal sector activities controls, Yes) label
}

 
**----------------------------------------------------------------------------**
**---Table 6: Tax registration -- Heterogeneity by firm visibility
**----------------------------------------------------------------------------**


reghdfe taxid worker_total_99 pciICindex_1 corrupt_worker99 $C_governance $X_ctrls $C_policy_ctrls  $C_GIS_ctrls light16_mean $C_geo  $econ_formal if thudn1>100000& thudn1<. ,  absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
outreg2 using "$result/Table6.xls", excel keep(worker_total_99 pciICindex_1 corrupt_worker99) ///
	nocons addtext(Sample, atBorder, Commune-pair FE, Yes, 3-digit Industry FE, Yes, Governance controls, Yes, Firm's controls, Yes, Commune's policy controls, Yes, Commune's GIS controls, Yes, Night-light Index 2016, Yes, Geographical controls, Yes, Formal sector activities controls, Yes) label replace


reghdfe taxid worker_total_99 corrupt_worker99 $X_ctrls if thudn1>100000& thudn1<.& econ_formal==1 , absorb(com_pairID ind3 communeID_2017) cluster(provinceID_2017 borderID) 
outreg2 using "$result/Table6.xls", excel keep(worker_total_99 corrupt_worker99) ///
	nocons addtext(Sample, atBorder, Commune-pair FE, Yes, 3-digit Industry FE, Yes, Firm's controls, Yes, Commune FE, Yes) label
		  		  

reghdfe taxid operation_hr pciICindex_1 corrupt_operation_hr  $C_governance $X_ctrls $C_policy_ctrls  $C_GIS_ctrls light16_mean $C_geo  $econ_formal if thudn1>100000& thudn1<. ,  absorb(com_pairID ind3) cluster(provinceID_2017 borderID)
outreg2 using "$result/Table6.xls", excel keep(operation_hr pciICindex_1 corrupt_operation_hr) ///
	nocons addtext(Sample, atBorder, Commune-pair FE, Yes, 3-digit Industry FE, Yes, Governance controls, Yes, Firm's controls, Yes, Commune's policy controls, Yes, Commune's GIS controls, Yes, Night-light Index 2016, Yes, Geographical controls, Yes, Formal sector activities controls, Yes) label
		  
		  
reghdfe taxid operation_hr corrupt_operation_hr $X_ctrls if thudn1>100000& thudn1<.& econ_formal==1, absorb(com_pairID ind3 communeID_2017) cluster(provinceID_2017 borderID) 
outreg2 using "$result/Table6.xls", excel keep(operation_hr corrupt_operation_hr) ///
	nocons addtext(Sample, atBorder, Commune-pair FE, Yes, 3-digit Industry FE, Yes, Firm's controls, Yes, Commune FE, Yes) label
***--------------------------------------------------*********
